package 日期与时间;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.MonthDay;

public class 日期api {
    public static void main(String[] args) {
        LocalDateTime date=LocalDateTime.now();
        System.out.println(date);//2022-04-13
        int year=date.getYear();
        int month=date.getMonthValue();
        int day= date.getDayOfMonth();
        System.out.println(year);//2022
        System.out.println(month);//4
        System.out.println(day);//13
        System.out.println(date.getDayOfYear());//一年中的第几天 103
        System.out.println(date.getDayOfWeek());//星期 wednesday
        System.out.println(date.getMonth());//APRIL月份
        System.out.println(date.getHour());//9 小时
        System.out.println(date.getMinute());//分 14
        System.out.println(date.getSecond());//秒 34
        System.out.println(date.getNano());//纳秒
        LocalTime sj=LocalTime.now();
        System.out.println(sj);
        System.out.println(sj.minusHours(1));//往后一小时
        System.out.println(sj.plusMinutes(1));//往后一分钟
        System.out.println(sj);//时间还是没变说明上面那个是有新的储存空间来储存
        LocalDate a=LocalDate.of(2022,04,15);
        LocalDate b=LocalDate.now();
        System.out.println(b.equals(a));//比较时间是否相等
        System.out.println(b.isBefore(a));//b时间是否在a时间之前
        System.out.println(b.isAfter(a));//b时间是否在a时间之后
        LocalDate g=LocalDate.now();
        MonthDay h=MonthDay.of(g.getMonthValue(),g.getDayOfMonth());
        System.out.println(h);
        MonthDay q=MonthDay.from(g);
        System.out.println(q);
    }
}
